|
|
|
| To actually allow the user to drop the item from the list box on the image, you need to check whether the source control is a list box and whether the Text property of the source (the list box) is equal to the same value in the Tag property of the image control. If theyre the same, you know the item can be dropped in the image control, which then removes the item from the list box. |
|
|
| Remove Items from the List Box 1. Double-click on the imaArrow image control. 2. Select the DragDrop event from the Procedures combo box. 3. Add the following code to this event: | | Sub imaArrow_DragDrop (Source As Control, X As Single, _
Y As Single)
If TypeOf Source Is ListBox Then
If Source.Text = imaArrow.Tag Then
Source.RemoveItem Source.ListIndex
End If
End If
End Sub |  | You now need to repeat these steps for each of the other image controls on the form. Of course, this results in a lot of duplicate code; instead, you could use a control array, which is our next topic of discussion. To see the completed sample form, check out Drag4.frm in the sample project for this chapter. |
|
|
|
|
|
|
Examples Filename: Drag4.frm |
|
|
|
|
|
|
|
|
Simplifying Drag and Drop |
|
|
|
|
|
|
|
|
The example you just created has a lot of duplicate code because you repeat the DragOver and the DragDrop events for each of the image controls. One way to simplify this is to create a control array out of the image controls on the form. Another problem with the preceding code is that youre loading the icon files from disk each time you want to use them. This is not very efficient. Instead, you should store these images in an ImageList control and retrieve the pictures from there. |
|
|
|
|
|